﻿<?php
class Slideshow extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct() {
		$this->cache = new Ecore_Cache();
		$this->clear = $this->cache->clear;
	}
	public function get($intAlbumId) {
		try {						
			$this->prepare('call slideshows_a_get(?)');		
			$this->bindParam(1, $intAlbumId, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::getAlbum - ' .$e->getMessage());			
			
		}
	}
	public function getAlbumForCombo($intType, $intStt=1) {
		try {						
			$this->prepare('call slideshows_a_get_combo(?,?)');		
			$this->bindParam(1, $intType, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intStt, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::getAlbumForCombo - ' .$e->getMessage());			
			
		}
	}
	public function getAll($intAdType, $intType, $intStatus, $strKeyword, $strStartDate, $strEndDate, $intOff, $intLimit, &$intTotal=0) {
		try {						
			$this->prepare('call slideshows_a_getall(?,?,?,?,?,?,?,?)');		
			$this->bindParam(1, $intAdType, PDO::PARAM_INT, 4);
			$this->bindParam(2, $intType, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intStatus, PDO::PARAM_INT, 4);
			$this->bindParam(4, $strKeyword, PDO::PARAM_INT, 50);
			$this->bindParam(5, $strStartDate, PDO::PARAM_STR, 10);
			$this->bindParam(6, $strEndDate, PDO::PARAM_STR, 10);
			$this->bindParam(7, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(8, $intLimit, PDO::PARAM_INT, 6);
			$arrResult 	= $this->fetchAll();
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::getAll - ' .$e->getMessage());
		}
	}
	public function getAllImg($intAlbumId, $intOff, $intLimit, &$intTotal=0) {
		try {
			
			$this->prepare('call slideshows_i_getall(?,?,?)');		
			$this->bindParam(1, $intAlbumId, PDO::PARAM_INT, 4);
			$this->bindParam(2, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intLimit, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::getAllImage - ' .$e->getMessage());			
			
		}
	}
	public function addAlbum($intType, $intAdminId, $strAlName, $strImage, $strName) {
		try {
			$this->prepare('call slideshows_a_add(?,?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $strAlName, PDO::PARAM_STR, 255);
			$this->bindParam(3, $strImage, PDO::PARAM_STR, 150);
			$this->bindParam(4, $strName, PDO::PARAM_STR, 255);
			$this->bindParam(5, $intType, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::addAlbum - ' . $e->getMessage());			
		}
	}	
	public function addImage($intType, $intAdminId, $intAlbumId, $strImage, $strName) {
		try {
			$this->prepare('call slideshows_i_add(?,?,?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intAlbumId, PDO::PARAM_STR, 11);
			$this->bindParam(3, $strImage, PDO::PARAM_STR, 150);
			$this->bindParam(4, $strName, PDO::PARAM_STR, 255);
			$this->bindParam(5, $intReturn=1, PDO::PARAM_INT, 4);
			$this->bindParam(6, $intType, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::addImage - ' . $e->getMessage());
			
		}
	}
	public function updateAlbum($intAdminId, $intAlbumId, $strName) {
		try {
			$this->prepare('call slideshows_a_update(?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intAlbumId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strName, PDO::PARAM_STR, 255);
			$arrResult 	= $this->fetchAll();		
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::update - ' . $e->getMessage());
			
		}
	}
	public function updateStatusAlbum($intAdminId, $intAlbumId, $intStatus, $intPerm) {
		try {				
			$this->prepare('call slideshows_a_update_status(?,?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intAlbumId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intStatus, PDO::PARAM_INT, 4);
			$this->bindParam(4, $intPerm, PDO::PARAM_INT, 4);
			$arrResult 	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::updateStatusAlbum - ' .$e->getMessage());			
			
		}
	}	
	public function deleteImage($intAdminId, $intImageId, $intAlbumId, $intType=0) {
		try {			
			$this->prepare('call slideshows_i_delete(?,?,?)');
			$this->bindParam(1, $intAdminId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intImageId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intAlbumId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$strImage = isset($arrResult[0]['image']) ? $arrResult[0]['image'] : '';
				if($strImage != '') {
					$this->deleteImg($strImage,$intType);
				}
			}
			return $intError;
		} catch(Exception $e) {
			Ecore_Function::logDb('Backend::Slideshow::deleteImage - ' .$e->getMessage());			
			
		}
	}
	public function deleteImg($str,$type) {
		$strFull 	= '';
		$strThumb	= '';
		$strSmall	= '';
		switch($type) {
			case EDUCATION_TYPE:
				break;
			case SHARE_TYPE:
				break;
		}
		if($strFull != '' && file_exists($strFull))
			@unlink($strFull);
		if($strThumb != '' && file_exists($strThumb))
			@unlink($strThumb);
		if($strSmall != '' && file_exists($strSmall))
			@unlink($strSmall);
	}
}